package org.com.ashen.web.voice.common.http.request;

import java.util.Map;

/**
 * Http请求实体
 * 
 * @author Frank
 *
 * @param <T>
 *            传输数据类型
 */
public abstract class EmayHttpRequest<T extends Object> {

	private String url;// URL
	private String charSet = "UTF-8";// 编码
	private String method = "GET";// Http方法
	private Map<String, String> headers;// 头信息
	private String cookies;// cookie信息
	private T params;// 传输数据

	private String password;
	private String keyStorePath;
	private String trustStorePath;
	private String algorithm;

	private boolean isHttps;

	/**
	 * Http请求
	 * 
	 * @param url
	 *            URL
	 * @param charSet
	 *            编码
	 * @param method
	 *            Http方法
	 * @param headers
	 *            头信息
	 * @param cookies
	 *            cookie信息
	 * @param params
	 *            传输数据
	 */
	public EmayHttpRequest(String url, String charSet, String method, Map<String, String> headers, String cookies, T params) {
		this.url = url;
		this.charSet = charSet;
		this.method = method;
		this.headers = headers;
		this.cookies = cookies;
		this.params = params;
		this.isHttps = false;
	}

	/**
	 * Https请求
	 * 
	 * @param url
	 *            URL
	 * @param charSet
	 *            编码
	 * @param method
	 *            Http方法
	 * @param headers
	 *            头信息
	 * @param cookies
	 *            cookie信息
	 * @param params
	 *            传输数据
	 * @param password
	 *            密钥库密钥
	 * @param keyStorePath
	 *            密钥库文件地址
	 * @param trustStorePath
	 *            信任库文件地址
	 * @param algorithm
	 *            指定交换数字证书的加密标准:JKS
	 */
	public EmayHttpRequest(String url, String charSet, String method, Map<String, String> headers, String cookies, T params, String password, String keyStorePath, String trustStorePath,
			String algorithm) {
		this(url, charSet, method, headers, cookies, params);
		this.password = password;
		this.keyStorePath = keyStorePath;
		this.trustStorePath = trustStorePath;
		this.algorithm = algorithm;
		this.isHttps = true;
	}

	/**
	 * 将传输数据转换为byte[]类型
	 * 
	 * @return
	 */
	public abstract byte[] paramsToBytesForPost();

	/**
	 * 将传输数据转换为String类型
	 * 
	 * @return
	 */
	public abstract String paramsToStringForGet();

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getCharSet() {
		return charSet;
	}

	public void setCharSet(String charSet) {
		this.charSet = charSet;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public Map<String, String> getHeaders() {
		return headers;
	}

	public void setHeaders(Map<String, String> headers) {
		this.headers = headers;
	}

	public String getCookies() {
		return cookies;
	}

	public void setCookies(String cookies) {
		this.cookies = cookies;
	}

	public T getParams() {
		return params;
	}

	public void setParams(T params) {
		this.params = params;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getKeyStorePath() {
		return keyStorePath;
	}

	public void setKeyStorePath(String keyStorePath) {
		this.keyStorePath = keyStorePath;
	}

	public String getTrustStorePath() {
		return trustStorePath;
	}

	public void setTrustStorePath(String trustStorePath) {
		this.trustStorePath = trustStorePath;
	}

	public String getAlgorithm() {
		return algorithm;
	}

	public void setAlgorithm(String algorithm) {
		this.algorithm = algorithm;
	}

	public boolean isHttps() {
		return isHttps;
	}

	public void setHttps(boolean isHttps) {
		this.isHttps = isHttps;
	}

}
